package org.aaron.demos;

import org.aaron.demos.service.TestService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ServiceActivity extends Activity {
	private Button open_service_btn, close_service_btn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.servicelayout);
		initActivity();
	}

	private void initActivity() {
		open_service_btn = (Button) this.findViewById(R.id.open_service_btn);
		open_service_btn.setOnClickListener(new ServiceOpenClickListener());
		close_service_btn = (Button) this.findViewById(R.id.close_service_btn);
		close_service_btn.setOnClickListener(new ServiceCloseClickListener());
	}

	class ServiceOpenClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Log.d("ServiceActivity", "ServiceOpenClickListener");
			Intent intent = new Intent();
			intent.setClass(ServiceActivity.this, TestService.class);
			ServiceActivity.this.startService(intent);
		}
	}

	class ServiceCloseClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Log.d("ServiceActivity", "ServiceCloseClickListener");
			Intent intent = new Intent();
			intent.setClass(ServiceActivity.this, TestService.class);
			ServiceActivity.this.stopService(intent);
		}
	}
}
